<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Styling with CSS</title>
<style>
  table {
    border-collapse: collapse;
    width: 100%;
  }

  th, td {
    border: 1px solid black;
    padding: 8px;
    text-align: left;
  }

  th {
    background-color: #f2f2f2;
  }

  tr:nth-child(even) {
    background-color: #f2f2f2;
  }
</style>
</head>
<a href="./1.php">日志</a>
<a href="./read_log.php">laravel</a>
<a href="http://81.69.250.186:9003/read_log.php">服务器laravel</a>
<a href="./test.php">php配置信息</a>

<?php
//  192.168.31.148:83/read_log.php
$dir = '../storage/logs';
function getDirFiles($dir) {
    $files = [];
    if ($handle = opendir($dir)) {
        while (false !== ($filename = readdir($handle))) {
            if ($filename != "." && $filename != "..") {
                if (is_dir($dir . "/" . $filename)) {
                    $subfiles = getDirFiles($dir . "/" . $filename);
                    $files = array_merge($files, $subfiles);
                } else {
                    $files[] = $dir . "/" . $filename;
                }
            }
        }
        closedir($handle);
    }
    return $files;
}

$listfilename=getDirFiles($dir);

krsort($listfilename);


if(isset($_GET['name'])&&!empty($_GET['name'])){
    $file_name=$_GET['name'];
    echo '<table border="1">';
    $content=file_get_contents($file_name);
    if($file_name=='../storage/logs/laravel.log'){
        $arr=explode("2025",$content);
        $arr=array_filter($arr);
        krsort($arr);
        echo '<table border="1">';
        foreach($arr as $v){
            $v='[2025'.$v;
            echo '<tr>'; // 开始表格行
            echo "<td>$v</td>";
            echo '</tr>'; // 结束表格行

        }
        echo "</table>";


        exit;

    }
    

    $arr= preg_split("/\r\n|\n/", $content);
    $arr=array_filter($arr);
    krsort($arr);

    echo '<table border="1">';
    foreach($arr as $v){
        $v_ar=explode(":",$v);
        $n3=$v_ar['3'];
        $n0=$v_ar['0'];
        $n1=$v_ar['1'];
        $n2=$v_ar['2'];
        $d=$n0.':'.$n1.':'.$n2;
        echo '<tr>'; // 开始表格行
        echo "<td>$n3</td>";
        echo "<td>$d</td>";
        echo '</tr>'; // 结束表格行

    }
    echo "</table>";

}else{
    echo '<table border="1">';
    foreach ($listfilename as &$v){

        if (strpos($v, '.log') !== false) {
            echo '<tr>'; // 开始表格行
            echo "<td><a href='./read_log.php?name=$v'>$v</a></td>";
            echo '</tr>'; // 结束表格行
        }

        

    }
    echo "</table>";

}



//var_dump($listfilename);exit;

?>